export const flattenArr = (arr) => {
    return arr.reduce((map, item) => {
        map[item.id] = item
        return map
    }, {})
}

export const objToArr = (obj) => {
    let keyList =  Object.keys(obj).sort((a, b) => {
        return  obj[a].index - obj[b].index
    })
    return keyList.map(key => obj[key])
}

export const getParentNode = (node, parentClassName) => {
    let current = node
    while(current) {
        if(current.classList && current.classList.contains(parentClassName)) {
            return current
        }
        current = current.parentNode
    }
    return false
}
// const newFiles = files.map(file => {
//   if(file.id === id) {
//     file.body = value
//   }
//   return file
// })
// const newFiles = files.filter(file => file.id !== id)

export const timestampTostring = (timestamp) => {
    const date = new Date(timestamp)
    return date.toLocaleDateString() + '' + date.toLocaleTimeString()
}